home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / lib / partman / commit.d / 01unmount_busy next >
Text File  |  2009-10-28  |  2KB  |  113 lines

  1. #! /bin/sh
  2.  
  3. # This should largely be unnecessary now that partman-base/init.d/parted
  4. # checks for mounted partitions at startup, but it may still serve as
  5. # insurance against partitions being mounted while the partitioner is
  6. # running.
  7.  
  8. . /lib/partman/lib/base.sh
  9.  
  10. db_get ubiquity/partman-skip-unmount
  11. if [ "$RET" = true ]; then
  12.     exit 0
  13. fi
  14.  
  15. if [ -f /etc/mtab ]; then
  16.     MTAB=/etc/mtab
  17. else
  18.     MTAB=/proc/mounts
  19. fi
  20.  
  21. busy_partitions=
  22.  
  23. for dev in $DEVICES/*; do
  24.     [ -d "$dev" ] || continue
  25.     cd $dev
  26.  
  27.     partitions=
  28.     found_mounted=false
  29.     open_dialog PARTITIONS
  30.     while { read_line num id size type fs path name; [ "$id" ]; }; do
  31.     [ "$fs" != free ] || continue
  32.     partitions="$partitions $id,$path"
  33.     if [ -f "$id/mountpoint" ]; then
  34.         mp="$(cat "$id/mountpoint")"
  35.         case $mp in
  36.         /media/*)
  37.             ;;
  38.         *)
  39.             found_mounted=:
  40.             ;;
  41.         esac
  42.     fi
  43.     done
  44.     close_dialog
  45.  
  46.     if ! $found_mounted; then
  47.     open_dialog IS_CHANGED
  48.     read_line changed
  49.     close_dialog
  50.     [ "$changed" = yes ] || continue
  51.     fi
  52.  
  53.     for part in $partitions; do
  54.     id="${part%,*}"
  55.     path="${part#*,}"
  56.     open_dialog IS_BUSY "$id"
  57.     read_line busy
  58.     close_dialog
  59.     [ "$busy" = yes ] || continue
  60.     busy_partitions="$busy_partitions $path"
  61.     done
  62. done
  63.  
  64. [ "$busy_partitions" ] || exit 0
  65.  
  66. noninteractive=:
  67. while :; do
  68.     failed_mountpoints=
  69.     for part in $busy_partitions; do
  70.     for mp in $(grep "^$part " "$MTAB" | cut -d' ' -f2); do
  71.         # This is impressively horrible, but it's the best way I can
  72.         # come up with to unmangle mtab entries in shell.
  73.         new_mp=
  74.         while [ "$mp" ]; do
  75.         case $mp in
  76.             \\[0-9][0-9][0-9]*)
  77.             octal="$(echo "$mp" | sed 's/^\\\([0-9][0-9][0-9]\).*/\1/')"
  78.             new_mp="$new_mp$(printf "\\$octal")"
  79.             mp="${mp#\\[0-9][0-9][0-9]}"
  80.             ;;
  81.             \\*)
  82.             new_mp="$new_mp\\"
  83.             mp="${mp#\\}"
  84.             ;;
  85.             *\\*)
  86.             new_mp="$new_mp${mp%%\\*}"
  87.             mp="\\${mp#*\\}"
  88.             ;;
  89.             *)
  90.             new_mp="$new_mp$mp"
  91.             mp=
  92.             ;;
  93.         esac
  94.         done
  95.         umount "$new_mp" || failed_mountpoints="${failed_mountpoints:+$failed_mountpoints }$new_mp"
  96.     done
  97.     done
  98.  
  99.     if [ -z "$failed_mountpoints" ]; then
  100.     break
  101.     fi
  102.  
  103.     db_reset ubiquity/partman-failed-unmount
  104.     db_subst ubiquity/partman-failed-unmount MOUNTED "$failed_mountpoints"
  105.     db_input critical ubiquity/partman-failed-unmount || $noninteractive
  106.     db_go || exit 1
  107.     db_get ubiquity/partman-failed-unmount
  108.     [ "$RET" = true ] || exit 1
  109.     noninteractive='exit 1'
  110. done
  111.  
  112. exit 0
  113.